home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 2 / CU Amiga Magazine's Super CD-ROM 02 (1996)(EMAP Images)(GB)[!][issue 1996-04].iso / magazine / amiga_e / amigae.sept.archive / 000018_crash!axion.bt.…uk!D.Higginson_Mon, 6 Sep 93 02:17:59 PST.msg < prev    next >
Text File  |  1993-11-02  |  6KB  |  165 lines

  1. Received: by bkhouse.cts.com (V1.16/Amiga)
  2.     id AA00000; Mon, 6 Sep 93 02:17:59 PST
  3. Received: from zaphod.axion.bt.co.uk by crash.cts.com with smtp
  4.     (Smail3.1.28.1 #18) id m0oZc73-0000fbC; Mon, 6 Sep 93 01:39 PDT
  5. Received: from elephant.axion.bt.co.uk by zaphod.axion.bt.co.uk with SMTP (PP); Mon, 6 Sep 1993 09:39:33 +0100
  6. Message-Id: <m0oZc73-0000fbC@crash.cts.com>
  7. Date: Mon, 06 Sep 93 09:39:31 BST
  8. From: D.Higginson@axion.bt.co.uk
  9. To: AmigaE@bkhouse.cts.com
  10. Subject: Scrolly Routine!
  11.  
  12. Hi all,
  13.  
  14. This program is a scroll routine which makes a horizontally
  15. scrolling pattern. It could be used as the basis for a
  16. horizontal shoot-'em-up.
  17.  
  18. How it works:
  19.  
  20. First, I set up a 784x200 low-res screen. This is more than
  21. twice the width of a normal low-res screen, and is NTSC so
  22. that all can use this example straight off.
  23.  
  24. There are 4 images, one blank and three differently coloured
  25. images. The data are those hexadecimal numbers - stored one
  26. bitplane at a time (two bitplanes). The images displayed in
  27. the demo are decided at random, but it would be easy to get
  28. the program to read this data from memory to produce a game.
  29.  
  30. Each VBL (vertical blank), one image is pasted just to the
  31. right of the visible area and one just to the left. This
  32. continues until that column is full of images. Pasting of the
  33. next row then starts after 4 VBLs because the images are 16
  34. pixels wide and the screen is only 12 blocks tall.
  35.  
  36. Each VBL the screen is shifted one pixel to the left using
  37. the ScrollVPort() function. This does not move any graphics
  38. data, it simply shifts the view that you have onto the
  39. screen's bitmap.
  40.  
  41. When a full screen has been built up, there is already a
  42. copy of the image because of the blocks that were pasted to
  43. the left of the visible portion. This means the screen can
  44. be flicked back and the whole process starts again.
  45.  
  46. The result is a very fast scroll routine, which is silky
  47. smooth even under Intuition (!). The only CPU time used each
  48. VBL is the time to paste one 16x16 image, making it feasible
  49. to produce a game based on many bitplanes. The variable
  50. SCROLLSPEED can be used to increase the speed of the scroll.
  51. Set it to 1, 2, 4 or 8 for best effects. This also signifies
  52. the number of 16x16 images drawn per VBL.
  53.  
  54. Although this example only works under KickStart 2.0+, it
  55. could be modified for earlier OS versions.
  56.  
  57. Enjoy!
  58.  
  59. Dave.
  60.  
  61. ------8<------8<------8<------8<------
  62. MODULE 'exec/memory',
  63.        'intuition/intuition','intuition/screens',
  64.        'graphics/text','graphics/view'
  65.  
  66. CONST NUMIMAGE=4,IMAGEDATASIZE=2*16*2,SCROLLSPEED=1
  67.  
  68. ENUM ER_NONE,ER_NOSCRN,ER_NOMEM
  69.  
  70. DEF s=NIL,w=NIL:PTR TO window,sprite=NIL,imagedata=NIL
  71.  
  72. PROC setupimages()
  73.   IF (imagedata:=AllocVec(NUMIMAGE*IMAGEDATASIZE,
  74.                           MEMF_CHIP OR MEMF_CLEAR))=NIL THEN Raise(ER_NOMEM)
  75.   CopyMemQuick([$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,
  76.                 $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,
  77.                 $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,
  78.                 $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,
  79.  
  80.                 $FFFF,$FFFF,$C003,$C003,$C003,$C003,$C3C3,$C3C3,
  81.                 $C3C3,$C3C3,$C003,$C003,$C003,$C003,$FFFF,$FFFF,
  82.                 $0000,$0000,$0000,$0000,$0000,$0000,$03C0,$03C0,
  83.                 $03C0,$03C0,$0000,$0000,$0000,$0000,$0000,$0000,
  84.  
  85.                 $0000,$0000,$0000,$0000,$0000,$0000,$03C0,$03C0,
  86.                 $03C0,$03C0,$0000,$0000,$0000,$0000,$0000,$0000,
  87.                 $FFFF,$FFFF,$C003,$C003,$C003,$C003,$C003,$C003,
  88.                 $C003,$C003,$C003,$C003,$C003,$C003,$FFFF,$FFFF,
  89.  
  90.                 $FFFF,$FFFF,$C003,$C003,$C003,$C003,$C003,$C003,
  91.                 $C003,$C003,$C003,$C003,$C003,$C003,$FFFF,$FFFF,
  92.                 $FFFF,$FFFF,$C003,$C003,$C003,$C003,$C3C3,$C3C3,
  93.                 $C3C3,$C3C3,$C003,$C003,$C003,$C003,$FFFF,$FFFF]:INT,
  94.                 imagedata,NUMIMAGE*IMAGEDATASIZE)
  95. ENDPROC
  96.  
  97. PROC setupscreen()
  98.   CloseWorkBench()
  99.   IF (s:=OpenScreenTagList(NIL,
  100.     [SA_WIDTH,784,SA_HEIGHT,200,SA_DEPTH,2,SA_DISPLAYID,0,
  101.      SA_QUIET,TRUE,SA_FONT,['topaz.font',8,0,0]:textattr,
  102.      SA_OVERSCAN,OSCAN_TEXT,
  103.      0,0]))=NIL THEN Raise(ER_NOSCRN)
  104.   IF (w:=OpenWindowTagList(NIL,
  105.     [WA_LEFT,0,WA_TOP,0,WA_WIDTH,784,WA_HEIGHT,256,
  106.      WA_IDCMP,0,
  107.      WA_FLAGS,WFLG_SIMPLE_REFRESH OR WFLG_NOCAREREFRESH OR
  108.               WFLG_BORDERLESS OR WFLG_ACTIVATE OR WFLG_RMBTRAP,
  109.      WA_CUSTOMSCREEN,s,
  110.      WA_MOUSEQUEUE,0,WA_RPTQUEUE,0,
  111.      0,0]))=NIL THEN Raise(ER_NOSCRN)
  112.   IF sprite:=AllocMem(20,MEMF_CHIP OR MEMF_CLEAR)
  113.     SetPointer(w,sprite,1,16,0,0)
  114.   ENDIF
  115.   LoadRGB4(ViewPortAddress(w),
  116.            [$000,$F00,$0F0,$FF0]:INT,16)
  117. ENDPROC
  118.  
  119. PROC shutdown()
  120.   IF w THEN CloseWindow(w)
  121.   IF sprite THEN FreeMem(sprite,20)
  122.   IF s THEN CloseScreen(s)
  123.   IF imagedata THEN FreeVec(imagedata)
  124.   OpenWorkBench()
  125. ENDPROC
  126.  
  127. PROC scroll()
  128.   DEF vp:PTR TO viewport,bigx,smallx,tile,imagenum,i,r,ypos
  129.   r:=w.rport
  130.   vp:=s+44
  131.   REPEAT
  132.     FOR bigx:=0 TO 384 STEP 16
  133.       IF Mouse()
  134.         Raise(ER_NONE)
  135.       ENDIF
  136.       FOR smallx:=0 TO 15 STEP SCROLLSPEED
  137.         PutInt(vp.rasinfo+8,32+bigx+smallx)
  138.         ScrollVPort(vp)
  139.         WaitTOF()
  140.         FOR tile:=0 TO SCROLLSPEED-1
  141.           IF smallx+tile<12
  142.             imagenum:=Rnd(NUMIMAGE)
  143.             ypos:=smallx+tile*16
  144.             i:=[0,0,16,16,1,imagenum*IMAGEDATASIZE+imagedata,3,0,NIL]:image
  145.             DrawImage(r,i,bigx,ypos)
  146.             DrawImage(r,i,bigx+400,ypos)
  147.           ENDIF
  148.         ENDFOR
  149.       ENDFOR
  150.     ENDFOR
  151.   UNTIL FALSE
  152. ENDPROC
  153.  
  154. PROC main() HANDLE
  155.   setupimages()
  156.   setupscreen()
  157.   scroll()
  158.   Raise(ER_NONE)
  159. EXCEPT
  160.   shutdown()
  161.   IF exception<>ER_NONE THEN WriteF('There was an error.\n')
  162. ENDPROC
  163. ------8<------8<------8<------8<------
  164.  
  165. Apologies for uncommented code (it was late :-)